#include<stdio.h>
#include<errno.h>
#include<unistd.h>
#include<iostream>
#include<sys/epoll.h>
#include<fcntl.h>




int main(){
  int epollfd=epoll_create(2);
  if(epollfd<0){
    perror("epoll_create");
    return 0;
  }
  struct epoll_event ts; 
  ts.events=EPOLLIN | EPOLLET;
  ts.data.fd=0;
  epoll_ctl(epollfd,EPOLL_CTL_ADD,0,&ts);

  int flag=fcntl(0,F_GETFL);
  fcntl(0,F_GETFL,flag|O_NONBLOCK);
  while(1){
    struct epoll_event arr[5];
    int ret= epoll_wait(epollfd,arr,5,-1);
    if(ret<0){
      perror("epoll_wait");
      continue;
    }
    for(int i =0; i<ret; i++){
      if(arr[i].data.fd==0){
  
        while(1){
        char buf[3]={0};

        ssize_t r_size= read(0,buf,sizeof(buf)-1);
        if(errno== EAGAIN || errno == EWOULDBLOCK){
          break;
        }
        //scanf("%s",buf);
        //if(r_size<sizeof(buf)-1){
        //break;
        //}
        printf("buf %s\n",buf);
      }

    }

  }
  return 0;
}
}


